package com.laotou99.backjack.test3;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.alibaba.fastjson.JSON;

public class MainTest2 {
	
	String [][] Maze1 = new String[10][12];
	int iDoor1,iDoor2,xDoor1,xDoor2,yDoor1,yDoor2;
	Random r1 = new Random(System.currentTimeMillis());
	List<Integer> lis1 = new ArrayList<>();
	
	public MainTest2(){
		int i1 = r1.nextInt(4);
		System.out.println("i1-=>"+i1);
		if(i1==0){
			i1++;
		}
		while(i1-->0){
			int i2 = r1.nextInt(10);
			if(i2==0)i2++;
			System.out.println("i2-=>"+i2);
			lis1.add(i2);
		}
		while(lis1.size()<4){
			lis1.add(-1);
		}
		System.out.println(lis1.size());
		System.out.println(JSON.toJSONString(lis1));
		wallAddToDoor(lis1);
	}
	
	private void wallAddToDoor(List<Integer> lis) {
		int irrr = r1.nextInt(4);
		switch (irrr) {
		case 0:
			xDoor1=lis.get(0);
			yDoor1=lis.get(1);
			xDoor2=lis.get(2);
			yDoor2=lis.get(3);
			break;
		case 1:
			xDoor1=lis.get(0);
			yDoor1=lis.get(2);
			xDoor2=lis.get(3);
			yDoor2=lis.get(1);
			break;
		case 2:
			xDoor1=lis.get(3);
			yDoor1=lis.get(1);
			xDoor2=lis.get(0);
			yDoor2=lis.get(2);
			break;
		case 3:
			xDoor1=lis.get(2);
			yDoor1=lis.get(0);
			xDoor2=lis.get(3);
			yDoor2=lis.get(1);
			break;
		default:
			break;
		}
		System.out.println("xDoor1-=>"+xDoor1+
				",xDoor2-=>"+xDoor2+",yDoor1-=>"+
				yDoor1+",yDoor2-=>"+yDoor2);
	}

	public void test1(){
		
	}
	
	public void buildMaze(){
		for(int i1 = 0;i1<Maze1.length;i1++){
			for(int i2=0;i2<Maze1[0].length;i2++){
				Maze1[i1][i2]=getPoint(i1,i2);
			}
		}
	}
	
	private String getPoint(int i1, int i2) { 
		if(i1==0 && i2==0){
			return "+";
		}
		if(i1==0 && i2==Maze1[0].length-1){
			return "+";
		}
		if(i1==Maze1.length-1&&i2==0){
			return "+";
		}
		if(i1==Maze1.length-1&&i2==Maze1[0].length-1){
			return "+";
		}
		if(i1==0 || i1==Maze1.length-1 ){
			if(i1==0 && i2==yDoor1){
				return ".";
			}
			if(i1==Maze1.length-1 && i2==yDoor2){
				return ".";
			}
			return "-";
		}
		if(i2==0 || i2==Maze1[0].length-1){
			if(i2==0 && i1==xDoor1){
				return ".";
			}
			if(i2==Maze1[0].length-1 && i1==xDoor2){
				return ".";
			}			
			return "|";
		}
		
		return ".";
	}

	public void showMaze1(){
		
		for(int i1 = 0;i1<Maze1.length;i1++){
			for(int i2=0;i2<Maze1[0].length;i2++){
				System.out.print(Maze1[i1][i2]);
			}
			System.out.println();
		}
	}

	public static void main(String[] args) {
		MainTest2 mt2 = new MainTest2();
		mt2.buildMaze();
		mt2.showMaze1();

	}

}
